//package com.fingard.dsp.bank.directbank.ccb04.util;
//
//import com.sun.org.apache.xml.internal.security.utils.Base64;
//
//import java.security.KeyFactory;
//import java.security.PrivateKey;
//import java.security.PublicKey;
//import java.security.spec.PKCS8EncodedKeySpec;
//import java.security.spec.X509EncodedKeySpec;
//
///**
// * Created by Lewis on 2017/11/22.
// * 签名算法: "MD5withRSA" 做签名验签
// */
//public class RSAHelper {
//    private static final String SIGN_ALGORITHMS = "MD5withRSA";
//    /**
//     * RSA签名
//     *
//     * @param content    待签名数据
//     * @param privateKey 商户私钥
//     * @param encode     字符集编码
//     * @return 签名值
//     */
//    public static String sign(String content, String privateKey, String encode) {
//        try {
//            PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(Base64.decode(privateKey));
//
//            KeyFactory keyf = KeyFactory.getInstance("RSA");
//            PrivateKey priKey = keyf.generatePrivate(priPKCS8);
//
//            java.security.Signature signature = java.security.Signature.getInstance(SIGN_ALGORITHMS);
//
//            signature.initSign(priKey);
//            signature.update(content.getBytes(encode));
//
//            byte[] signed = signature.sign();
//
//            return Base64.encode(signed);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//        return null;
//    }
//
//    /**
//     * RSA验签名检查
//     *
//     * @param content   待签名数据
//     * @param sign      签名值
//     * @param publicKey 分配给开发商公钥
//     * @param encode    字符集编码
//     * @return 布尔值
//     */
//    public static boolean verifySignData(String content, String sign, String publicKey, String encode) {
//        try {
//            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
//            byte[] encodedKey = Base64.decode(publicKey);
//            PublicKey pubKey = keyFactory.generatePublic(new X509EncodedKeySpec(encodedKey));
//
//
//            java.security.Signature signature = java.security.Signature
//                    .getInstance(SIGN_ALGORITHMS);
//
//            signature.initVerify(pubKey);
//            signature.update(content.getBytes(encode));
//
//            boolean bverify = signature.verify(Base64.decode(sign));
//            return bverify;
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//        return false;
//    }
//
//    public static void main(String args[]){
//        //签名验签测试
//        String pubkey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDK1yd7HVEx2rfB3pdWCtPTpnJRnV9QcQfPsKS1\n" +
//                "oNKCuDkgug/bZeSuzBNv2C3j2H/7jaT1g+g8WU9oLF+JIuL+P0fyMkcabXDk9aovA8NGNVSM/9/D\n" +
//                "9/MVD6xh2VnZOQ9glzD1TkYKWxan/GuNBRwAfrm96wloayEfHt9Cwbh0RwIDAQAB";
//        String privatekey = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMrXJ3sdUTHat8Hel1YK09OmclGd\n" +
//                "X1BxB8+wpLWg0oK4OSC6D9tl5K7ME2/YLePYf/uNpPWD6DxZT2gsX4ki4v4/R/IyRxptcOT1qi8D\n" +
//                "w0Y1VIz/38P38xUPrGHZWdk5D2CXMPVORgpbFqf8a40FHAB+ub3rCWhrIR8e30LBuHRHAgMBAAEC\n" +
//                "gYBvUqXYa76kHeW8AO4NyuN2xWL4Z+Znv6EJ22iKRjlChNjVnUgWoVVgmaARQhPteGTFKnfeRwau\n" +
//                "GFX8Vl4YZY0uAMPV0fGDX/8G8Ts9ki85lBUicB33DkzkZMCkjLmhjuEfpeuH19fju4MCEFwyGDOy\n" +
//                "qu3oFBDd/AdiH/s2QQZ8AQJBAP+oYPo+kbBKjl84gnEJTT+qB1bDBjL4KwfARuSCA7lQZyrpVMM3\n" +
//                "Q1wJx/2c9VbbRY5BQ5Te05sj9WYqSrZEe/0CQQDLHKxlE8Uyp+IWbbJmOPpNedlwK36X2x9tsbuo\n" +
//                "jp87ZkXmR00o5VtbPoshqpbaKz5dkAeIUsQYJmZ7AOHAUOqTAkEA1QsmjUKYu3TVwangoXuj4Pq6\n" +
//                "lOV+A/lkOlhTe1aQ7dt/rXW1idxCiK8p9kDW/eNJyiq+u48YfT7w34s8qTjWrQJBALaYZ29S77QT\n" +
//                "c1Bge8IkNPmTsmOB5oPUTRPLdX4aAZJf5jUYIojCcHe96Uxx1L37pExuoCbw6TMgyn6IE2tWExsC\n" +
//                "QCA6PE+1cnPKaz+BAtVCxeNvNA0EmB3lNhaoYn+2iSKl5Z9jcjSuE6TLC67fX8H3WDEgoNATM/V5\n" +
//                "AeUhzoTRLZs=\n";
//        String signdata = sign("您好",privatekey,"utf-8");
//        System.out.println("签名后的数据"+signdata);
//        boolean success = verifySignData("您好",signdata,pubkey,"utf-8");
//        System.out.print("验签结果:"+success);
//    }
//}
